#version 460

layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texCoords;
layout(location = 2) in vec3 normal;
layout(location = 3) in vec3 tangent;
layout(location = 4) in vec3 bitangent;

layout(location = 0) out vec3 out_fragPos;
layout(location = 1) out vec3 out_normal;
layout(location = 2) out vec2 out_texCoords;
layout(location = 3) out mat3 out_TBN;
layout(location = 6) out flat vec3 out_TangentViewPos;
layout(location = 7) out vec3 out_TangentFragPos;

layout(binding = 6) uniform MVP {
    mat4 model;
    mat4 view;
    mat4 proj;
    vec3 view_pos;
};


void main() {
    out_TBN = mat3(normalize(vec3(model * vec4(tangent, 0.0))), normalize(vec3(model * vec4(bitangent, 0.0))), normalize(vec3(model * vec4(normal, 0.0))));

    mat3 TBNi = transpose(out_TBN);

    out_fragPos = vec3(model * vec4(position, 1.0));
    out_normal = normalize(mat3(transpose(inverse(model))) * normal);
    out_texCoords = texCoords;
    out_TangentViewPos = TBNi * view_pos;
    out_TangentFragPos = TBNi * out_fragPos;

    gl_Position = proj * view * vec4(out_fragPos, 1.0);
}
